<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:max="http://www.w3.org/1999/xhtml"
      xmlns:min="http://www.w3.org/1999/xhtml">
<head>
    <th:block th:include="include :: header('编辑商铺')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div id="app" class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-product-add" enctype="multipart/form-data" >
        <input type="hidden" name="score_id" >
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商铺名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="name"th:value="${store.name}" id="name" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商铺地址：</label>
            <div class="col-sm-8">
<!--                <select class="form-control" id="location_id"th:value="${store.location_id}" name="location_id" >-->
<!--                </select>-->
                <select class="form-control" name="location_id" id="location_id" >
                    <option value="">所有</option>
                    <option   th:each="location :${locations}" th:text="${location.name}" th:value="${location.id}" th:selected="${store.location_id eq location.id}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商铺评分：</label>
            <div class="col-sm-8">
                <input class="form-control " type="text" name="score"th:value="${store.score}" id="score"  required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">评分人数：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="count" th:value="${store.count}" id="count" required>
            </div>
        </div>
    </form>
</div>
<h1 ></h1>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    $(document).ready(function(){
        $.ajax({
            url:  ctx + "/evaluation/location/locationList",
            type: "post",
            dataType: "json",
            success:function(data){
                console.log(data.value);
                for (var i = 0; i < data.locations.length; i++) {
                    //先创建好select里面的option元素
                    var option = document.createElement("option");
                    //给option的text赋值,这就是你点开下拉框能够看到的东西
                    $(option).text(data.locations[i].name);
                    $(option).val(data.locations[i].id);
                    $('#location_id').append(option);
                }
            },
            error:function (data) {
                console.log(data);
            }
        });
    });
</script>
<script type="text/javascript">
    var prefix = ctx+"evaluation";
    function submitHandler() {
        var name = $("#name").val();
        if (name=="" || name==null){
            $.modal.alertError("请输入商铺名");
            return;
        }
        var locationID = $("#location_id").val();
        console.log(locationID);
        if (locationID=="" || locationID==null){
            $.modal.alertError("请选择商铺地址");
            return;
        }
        var score = $("#score").val();
        if (score<0||score>100){
            $.modal.alertError("评分需在[0~100]之间");
            return;
        }
        var count = $("#count").val();
        if (count<=0){
            $.modal.alertError("人数需要大于0");
            return;
        }

        var form = $('#form-product-add')[0];
        console.log(form);
        var data = new FormData(form);
        console.log(data);
        console.log(data.name);
        var id = [[${store.id}]];
        var url = prefix+"/editStore2/"+id;
        $.operate.save1(url,data);
    }
</script>



</body>
</html>
